class Patient < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    name :string
    surname :string
    pesel :Bignum, :unique
    email_address :email_address
    address :string
    phone :integer
    timestamps
  end

  belongs_to :user
  has_many :order_examinations


  # --- Validation --- #
  validates_presence_of :name, :surname, :pesel, :email_address, :address, :phone
  validates_numericality_of :phone
  validates_numericality_of :pesel
  validates_length_of :pesel, :is => 11, :message => " must be 11-digit number"

  
  # --- Permissions --- #

  def create_permitted?
    acting_user.recepcionista?
  end

  def update_permitted?
    acting_user.recepcionista?
  end

  def destroy_permitted?
    acting_user.recepcionista?
  end

  def view_permitted?(field)
    acting_user.recepcionista? || acting_user.diagnosta? || acting_user.technik?
  end

end
